package br.com.transitojp.dao;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**  dom4j
 * HibernateUtil.java - this class help the other DAO classes to use the SessionFactory.  
 * @author LAViD - Laboratório de Aplicação de Vídeo Digital.
 * @version 1.0 
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
    
    /**  
	 * All that will be executed as soon as this class is initialized  
	 */
    static {
        try {
            sessionFactory =  new AnnotationConfiguration().configure().buildSessionFactory();  
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    /**  
	 * The purpose of this method is to retrieve the value of sessionFactory.  
	 * @return A SessionFactory data type.  
	 */
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
	
}